$(()=> {
    $('.form-contain .form-item .captcha-graph-img img').click(function () {
        $(this).attr('src', '/image_code/?rand=' + Math.random())
    });
    // 1. 检验用户名输入是否符合设定
   let isUsernameReady = false,
       isPassworldReady = false,
       isMobileReady = false;
   let $username = $('#username');
   $username.blur(fncheckusername);
   function fncheckusername(){
       isUsernameReady = false;
       let susername = $username.val();
       if (susername === ''){
           message.showError("用户名不能为空");
           return
       }
       if (!(/^\w{5,20}$/).test(susername)){
           message.showInfo('用户名格式不正确！');
           return
       }
       $.ajax({
           url : 'username/' + susername +'/',
           type : true,
           datatype : json,
           success : function (res) {
               if (res.data.count !== 0){
                   message.showError($username + '已注册，请重新输入！');
               }
               else{
                   message.showInfo('你真幸运，取到了一个好名字');
                   isUsernameReady = true
               }
           },
           error:function () {
               message.showInfo('连接超时，请检查网络！')
           }
       })
   }
   // 2. 检查密码两次输入是否一样
    let $password_repeat = $(' input[name = "password_repeat"]');
    let $password = $(' input[name = "password"]');
    $password.blur(fncheckpassword);
    function fncheckpassword() {
        let Password = $password.val();
        if (Password === '') {
            message.showInfo('请输入密码')
        }}
    $password_repeat.blur(fncheckrepeat);
    function fncheckrepeat() {
        let $password = $(' input[name = "password"]'),
            Repeat = $password_repeat.val(),
            Password = $password.val();
        if (Repeat !== Password) {
            message.showError('两次输入密码不一致！');}
        if (Repeat === '') {
            message.showInfo('请输入密码')}}

    // 3. 检验手机输入是否符合设定
    let $mobile = $(' input[name="mobile"]');
    $mobile.blur(fncheckmobile);
    function fncheckmobile() {
        isMobileReady = false;
        let sMobile = $mobile.val();
        if (sMobile === '') {
            message.showError('手机号不能为空，请填写！');
            return}
        if (!(/1[3,9]\d{9}/).test(sMobile)) {
            message.showInfo(sMobile + ',此号码格式不正确！');
            return}
        $.ajax({
            url: "mobile/" + sMobile + '/',
            type: true,
            datatype: json,
            success: function (res) {
                if (res.data.count !== 0)
                    message.showError('手机号已经注册，请重新输入！');},
            error: function () {
                message.showInfo('连接超时，请检查网路')}
        })
    }
});